/*	Author		: Arga
 *	Created On	: Apr 25, 2011
 *	Description	: 
 */

package team8.paacdroid.adapter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import team8.paacdroid.R;
import team8.paacdroid.bean.BusRide;
import team8.paacdroid.bean.Schedule;
import android.content.Context;

import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

@SuppressWarnings("rawtypes")
public class ScheduleAdapter extends ArrayAdapter<HashMap<String, String>> {
	private ArrayList<HashMap<String, String>> items;

	public ScheduleAdapter(Context context, int textViewResourceId, ArrayList<HashMap<String, String>> items) {
		super(context, textViewResourceId, items);
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		
		// Pop up the view
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.schedule_item, null);
		}
		
		// Get the Schedule to display
		HashMap<String, String> i = items.get(position);
		if (i != null) {
			// Get the widgets
			TextView tvStopName = (TextView) v.findViewById(R.id.tvStopName);
			TextView tvStopTimes = (TextView) v.findViewById(R.id.tvStopTimes);
			
			// Load and display stop name and area name
			tvStopName.setText(i.get("stopName") != null ? i.get("stopName").toString() : "");
			tvStopName.setText(i.get("areaName") != null ? tvStopName.getText() + " (" + i.get("areaName").toString() + ")" : tvStopName.getText());
			
			// Load and display the stop times
			tvStopTimes.setText(Html.fromHtml(i.get("stopTimes") != null ? i.get("stopTimes").toString() : ""));
		}

		// Return
		return v;
	}
}
